﻿using MediatR;
using Production_Get.API.DTO;
using Production_Get.API.Infrastructures.Interfaces;
using Return.Enum;
using THE_WIND_RISES.Common.Domans.Produce.Resources;
using THE_WIND_RISES.Common.Dtos;

namespace Production_Get.API.Application.Commands
{
    /// <summary>
    /// 资源管办反填
    /// </summary>
    public class ResourceManaHandler : IRequestHandler<ResourceManaCommend, Result>
    {
        private readonly IBaseRepositoryGet<Resource> Resource;

        public ResourceManaHandler(IBaseRepositoryGet<Resource> Resource)
        {
            this.Resource = Resource;
        }

        public async Task<Result> Handle(ResourceManaCommend request, CancellationToken cancellationToken)
        {
            var result = new Result() { Code = (int)CommonErrorCodes.Search };

            string sql = "SELECT * FROM Resource where ResourceId="+ request.ResourceId;
            var list= Resource.GetAll(sql,default).FirstOrDefault();
            if (list != null)
            {
                result.Code = (int)CommonErrorCodes.Success;
                result.Data = list;
                result.Msg = "反填成功";
            }

            return result;
        }
    }
}
